﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Management;
using System.Management.Instrumentation;

namespace Test4ReadNetCard
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            label1.Text += "CPU: " + GetCPUInfo() + Environment.NewLine;
            label1.Text += "HDD: " + GetHDDInfo() + Environment.NewLine;
            label1.Text += "MAC: " + GetMAC() + Environment.NewLine;
        }

        private string GetCPUInfo()
        {
            string cpuinfo = string.Empty;
            ManagementClass mc = new ManagementClass("Win32_Processor");
            ManagementObjectCollection moc = mc.GetInstances();
            foreach (ManagementObject mo in moc)
            {
                cpuinfo += mo.Properties["ProcessorId"].Value.ToString() + Environment.NewLine;
            }
            return cpuinfo;
        }

        private string GetHDDInfo()
        {
            string HDid = string.Empty;
            ManagementClass mc = new ManagementClass("Win32_DiskDrive");
            ManagementObjectCollection moc = mc.GetInstances();
            foreach (ManagementObject mo in moc)
            {
                HDid += mo.Properties["Model"].Value.ToString() + Environment.NewLine;
            }
            return HDid;
        }

        private string GetMAC()
        {
            string macInfo = string.Empty;
            ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
            ManagementObjectCollection moc = mc.GetInstances();
            foreach (ManagementObject mo in moc)
            {
                if ((bool)mo["IPEnabled"] == true)
                    macInfo += mo["MacAddress"].ToString() + Environment.NewLine;
            }
            return macInfo;
        }
    }
}
